<template>
  <div style="height: 100%; width: 100%; position: relative">
      <div class="pagetop">
          <template>
              <div style="width: 100%">
                  <table style="width: 100%">
                      <tr>
                          <td>
                              <table style="font-size: 12px" class="table1style">
                                  <tr>
                                      <td>入库时间</td>
                                      <td style="width: 130px"><el-date-picker v-model="inlibtimebegin" type="date" placeholder="开始日期" value-format="yyyy-MM-dd" size="mini" :clearable="false" style="width: 100%"></el-date-picker>~</td>
                                      <td>
                                          <el-date-picker v-model="inlibtimeend" type="date" placeholder="结束日期" value-format="yyyy-MM-dd" size="mini" :clearable="false" style="width: 160px"></el-date-picker>
                                      </td>
                                      <td style="text-align: right">条&ensp;码&ensp;号</td>
                                      <td style="width: 130px">
                                          <el-input style="width: 130px" v-model="qbarcode" ref="qbarcode" :clearable="true" @keyup.enter.native="Query()"></el-input>
                                      </td>
                                      <td style="text-align: right">病&ensp;历&ensp;号</td>
                                      <td style="width: 130px">
                                          <el-input style="width: 130px" v-model="patno" ref="patno" :clearable="true" @keyup.enter.native="Query()"></el-input>
                                      </td>
                                      <td style="text-align: right; ">报告单元</td>
                                      <td colspan="3" style="width: 339px">
                                          <rm-ddl-rptunit prgno="LIS351" ref="rptunitid" v-model="rptunitid" width="100%" :clearable="true" defaultflag="1" @change="rptunitChange"></rm-ddl-rptunit>
                                      </td>
                                      <td></td>
                                      <td></td>
                                      <td></td>
                                      <td></td>
                                      <td></td>
                                      <td></td>
                                  </tr>
                                  <tr>
                                      <td>库&ensp;位&ensp;号</td>
                                      <td>
                                          <el-select v-model="idhead" style="width: 130px" :clearable="true">
                                              <el-option value="" label=""></el-option>
                                              <el-option :key="item.value" :value="item.value" :label="item.label" v-for="item in headOption"></el-option>
                                          </el-select>
                                      </td>
                                      <td><el-input style="width: 75px" v-model="idnumberbegin" @keyup.enter.native="NextFocus(1)" ref="input1"></el-input> ~<el-input style="width: 75px" v-model="idnumberend" ref="input2"></el-input></td>
                                      <td style="text-align: right">姓&ensp;&ensp;&ensp;&ensp;名</td>
                                      <td><el-input style="width: 130px" v-model="pat_name" @keyup.enter.native="Query()"></el-input></td>
                                      <td style="text-align: right">病人类型</td>
                                      <td colspan="1" style="width: 130px">
                                          <rm-ddl-common datatype="seccode" kindno="PT" v-model="pttypecode" width="130px" @change="pattypeChange"></rm-ddl-common>
                                      </td>
                                      <!--
                                      <td>
                                          <td><el-checkbox v-model="isfullcontent" true-label="1" false-label="0">项目全满足</el-checkbox></td> 
                                      </td> -->
                                      <td :class="DateBackGround()" style="text-align: right">检验日期</td>
                                      <td :class="DateBackGround()">
                                          <el-date-picker v-model="sampledate" type="date" placeholder="检验日期" value-format="yyyy-MM-dd" size="mini" :clearable="false" style="width: 130px" :picker-options="pickerOptions"></el-date-picker>
                                      </td>
                                      <td>起始标本号</td>
                                      <td>
                                          <el-input style="width: 130px" v-model="sampleno" ref="newsampleno"></el-input>
                                      </td>
                                      <td></td>
                                      <td></td>
                                      <td></td>
                                      <td></td>
                                      <td></td>
                                      <td></td>
                                  </tr>
                                  <tr>
                                      <td>项目组合</td>
                                      <td>
                                          <rm-ddl-common datatype="reportitemcomb" dataname="项目组合" v-model="sel_itemcombid" width="100%" :labgroupid="labgroupid" @change="reportitemcombchange"></rm-ddl-common>
                                      </td>
                                      <td>
                                          <el-select v-model="isbranchsampleNo" style="width: 160px" @change="branchsampleNochange($event)">
                                              <el-option value="0" label="全部信息"></el-option>
                                              <el-option value="1" label="已生成报告信息"></el-option>
                                              <el-option value="2" label="已生成需复查报告信息"></el-option>
                                              <el-option value="3" label="未生成报告信息"></el-option>
                                          </el-select>
                                      </td>
                                      
                                      <td style="text-align: right">报告项目</td>
                                      <td><rm-ddl-rptitem prgno="LIS351" :germmode="false" v-model="rptitemcode" width="100%" :appendtobody="true"  @change="rptitemChange"></rm-ddl-rptitem></td>
                                       <td style="text-align: right">排序方式</td>
                                      <td>
                                          <el-select v-model="sortorder" style="width: 130px" :clearable="true" >
                                              <el-option value="" label=""></el-option>
                                              <el-option :key="item.data" :value="item.data" :label="item.display" v-for="item in sortOption"></el-option>
                                          </el-select>
                                      </td>
                                      <td colspan="2"  style="text-align: right">
                                          <el-checkbox v-model="isautorank" true-label="1" false-label="0">输入样本号后自动往下排列</el-checkbox>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td>检测日期</td>
                                      <td style="width: 130px"><el-date-picker v-model="sampledatebegin" type="date" placeholder="开始日期" value-format="yyyy-MM-dd" size="mini" :clearable="true" style="width: 100%" :picker-options="pickerOptions"></el-date-picker>~</td>
                                      <td>
                                          <el-date-picker v-model="sampledateend" type="date" placeholder="结束日期" value-format="yyyy-MM-dd" size="mini" :clearable="true" style="width: 160px" :picker-options="pickerOptions"></el-date-picker>
                                      </td>
                                      <td style="text-align: right">工&ensp;作&ensp;组</td>
                                      <td><rm-ddl-common :appendtobody="true" datatype="labgroup" :clearable="false" dataname="检验工作组" v-model="labgroupidval" width="100%" :disabled="true"></rm-ddl-common></td>
                                     
                                      <td colspan="2"><el-checkbox v-model="isallcontain" true-label="1" false-label="0">包含全部已勾选的报告项目</el-checkbox></td>
                                      
                                      <td></td>
                                      <td></td>
                                      <td></td>
                                      <td></td>
                                      <td></td>
                                      <td></td>
                                  </tr>
                                  <td colspan="5" style="text-align: center">
                                      <el-button type="primary" @click="Query()" icon="el-icon-search">查询</el-button>
                                      <el-button @click="btnExport()" icon="el-icon-download">导出</el-button>
                                      <el-button @click="printBtn(1)" icon="el-icon-printer" :disabled="!printUseFlag">打印</el-button>
                                      <el-button @click="printBtn(2)" :disabled="!printUseFlag">打印设计</el-button>
                                  </td>
                                  <td></td>
                                  <td colspan="10" style="text-align: center">
                                      <el-button @click="branchsampleno()" :disabled="!bUseFlag">分配样本号</el-button>
                                      <el-button @click="onmachinedetection()" :disabled="!bUseFlag">上机/检测</el-button>
                                      <el-button @click="clearsampleno()" :disabled="!bUseFlag">清空样本号</el-button>
                                      <el-button @click="setnegative()" :disabled="!bUseFlag">一键阴性(-)</el-button>
                                      <el-button @click="ShowInusedSampleno()">查看已使用标本号</el-button>
                                  </td>
                                  <td style="text-align: center; width: 130px"></td>
                              </table>
                          </td>
                      </tr>
                  </table>
              </div>
          </template>
      </div>
      <div class="pagecenter">
          <div class="middle-left">
              <vxe-table ref="itemtable" :data.sync="itemData" :loading="itemloading" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow resizable size="mini" show-header-overflow show-overflow="ellipsis" :keyboard-config="keyConfig" header-align="center">
                  <vxe-table-column type="selection" width="40" align="center"></vxe-table-column>
                  <!-- <vxe-table-column align="center" type="index" title="序号" width="40"></vxe-table-column> -->
                  <vxe-table-column field="rpt_itemname" sortable title="报告项目名称" width="180"></vxe-table-column>
                  <vxe-table-column field="rpt_itemcode" sortable title="项目代码" width="100"></vxe-table-column>
                  <!-- <vxe-table-column field="rptunitname" sortable title="默认报告单元" width="100"></vxe-table-column> -->
              </vxe-table>
          </div>
          <div class="middle-center" style="height: calc(100% - 50px)">
              <vxe-table
                  ref="mainTable"
                  :data.sync="mainData"
                  :loading="mainloading"
                  :select-config="{ reserve: true }"
                  :sort-config="{ trigger: 'cell' }"
                  :edit-config="{
                      trigger: 'click',
                      mode: 'cell',
                  }"
                  border
                  height="auto"
                  highlight-current-row
                  highlight-hover-column
                  highlight-hover-row
                  how-header-overflow
                  resizable
                  size="mini"
                  show-header-overflow
                  show-overflow="ellipsis"
                  header-align="center"
                  @edit-actived="ResultActive"
                  @edit-closed="ResultClose"
                  @current-change="DataSelect"
                  :span-method="rowspanMethod"
              >
                  <!-- <vxe-table-column field="tbindex" title="序号" width="40" align="center" sortable></vxe-table-column> -->
                  <vxe-table-column field="seqno" title="序号" width="60" align="center"></vxe-table-column>
                  <vxe-table-column field="inlib_dt" sortable title="入库日期" width="90" :formatter="['toDateString', 'yyyy-MM-dd']" align="center"></vxe-table-column>
                  <vxe-table-column field="workid" sortable title="库位号" width="85" align="center"></vxe-table-column>
                  <vxe-table-column field="barcode" sortable title="条码号" width="100"></vxe-table-column>
                  <vxe-table-column field="showsampleno" sortable title="上机标本号" width="90" :edit-render="{ name: 'input', autoselect: true }">
                      <template v-slot:edit="{ row }">
                          <el-input v-if="isresultstredit" v-model="row.showsampleno" @change="samplenochange(row)"></el-input>
                          <div v-else>{{ row.showsampleno }}</div>
                      </template>
                  </vxe-table-column>
                  <vxe-table-column field="rpt_itemname" sortable title="报告项目" width="120"></vxe-table-column>
                  <vxe-table-column field="result_str" sortable title="检验结果" width="90" :edit-render="{ name: 'input', autoselect: true }">
                      <template v-slot="{ row }">
                          <div :style="ResultClass(row)">
                              <span>{{ row.result_str }}</span>
                          </div>
                      </template>
                      <template v-slot:edit="{ row, rowIndex }">
                          <el-input v-if="isresultstredit" v-model="row.result_str" style="width: 100%;18px" ref="rinput" @keyup.up.native="ResultMove(row, 0, rowIndex, 'result_str')" @keyup.down.native="ResultMove(row, 1, rowIndex, 'result_str')" @keyup.enter.native="resultenter(rowIndex)">
                              <i :class="iconclass" slot="suffix" @click="handleIconClick" v-show="tableDataResultAll.length > 0"></i>
                          </el-input>
                          <div v-else :style="ResultClass(row)">
                              <span>{{ row.result_str }}</span>
                          </div>
                          <div ref="selectDialog" class="reqitem-dialog" v-show="textvalueshow && isresultstredit" style="width: 100%; min-width: 240px">
                              <div class="reqitem-select">
                                  <vxe-table :data.sync="tableDataResultAll" max-height="250px" stripe resizable header-align="center" show-header-overflow highlight-hover-row :keyboard-config="keyConfig" show-overflow="ellipsis" size="mini" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" @cell-click="ResultTextClick($event, row)" status-msg-group="none" class="ResultTxtTable">
                                      <vxe-table-column field="textvalue" title="文字结果" width="160px" align="left" header-align="center" show-overflow-tooltip>
                                          <template v-slot="{ row }">
                                              <div :style="ResultClass(row)">
                                                  <span>{{ row.textvalue }}</span>
                                              </div>
                                          </template>
                                      </vxe-table-column>

                                      <vxe-table-column field="inputcode" title="输入码" width="80px" align="center" show-overflow-tooltip></vxe-table-column>
                                      <vxe-table-column field="result_flag" title="结果标志" width="80px" align="center" show-overflow-tooltip>
                                          <template v-slot="{ row }">
                                              <span>{{ ReusltflagName(row.result_flag) }}</span>
                                          </template>
                                      </vxe-table-column>
                                      <vxe-table-column field="seq" title="序号" width="40px" align="center" show-overflow-tooltip></vxe-table-column>
                                      <vxe-table-column field="containtext" title="录入码" width="100px" align="center" show-overflow-tooltip></vxe-table-column>
                                  </vxe-table>
                              </div>
                          </div>
                      </template>
                  </vxe-table-column>
                  <vxe-table-column field="sample_items" sortable title="申请项目(简称、部分)" width="200"></vxe-table-column>
                  <vxe-table-column field="inputresult" sortable title="上机结果" width="100"></vxe-table-column>
                  <vxe-table-column field="prereport_dt" sortable title="预出报告时间" width="120">
                      <template v-slot="{ row }">
                          <div :style="predtClass(row)">
                              <span>{{ row.prereport_dt }}</span>
                          </div>
                      </template>
                      <template slot="header" slot-scope="scope">
                          <span>预出报告时间
                              <el-tooltip :aa="scope" class="item" effect="dark" :content="txtcontent" placement="top-start" >
                          <i class="el-icon-question" style="color: #606266"> </i> </el-tooltip> </span> 
                      </template>
                  </vxe-table-column>
                  <vxe-table-column field="rptitemgroups" sortable title="项目归类编号" width="120"></vxe-table-column>
             
                  <vxe-table-column field="pat_name" sortable title="姓名" width="90"></vxe-table-column>
                  <vxe-table-column field="pat_sexname" sortable title="性别" width="60"></vxe-table-column>
                  <vxe-table-column field="pat_agestr" sortable title="年龄" width="65"></vxe-table-column>
                  <vxe-table-column field="libstatusname" sortable title="库位状态" width="65"></vxe-table-column>
                  <vxe-table-column field="workstatusname" sortable title="报告状态" width="65"></vxe-table-column>
                  <vxe-table-column field="pat_no" sortable title="病历号" width="100"></vxe-table-column>
                  <vxe-table-column field="req_groupna" sortable title="分单类别" width="100"></vxe-table-column>
                  <vxe-table-column field="specimen_name" sortable title="标本类型" width="100"></vxe-table-column>
                  <vxe-table-column field="emer_flagname" sortable title="加急" width="100"></vxe-table-column>
                  <vxe-table-column field="pat_typecodename" title="病人来源" width="60"></vxe-table-column>
                  <vxe-table-column field="req_docnoname" title="申请医生" width="60" align="center"></vxe-table-column>
                  <vxe-table-column field="req_dt" title="申请时间" width="120" align="center"></vxe-table-column>
                  <vxe-table-column field="inlib_username" title="入库人" width="60" align="center"></vxe-table-column>
                  <vxe-table-column field="req_stat" title="状态" width="80" align="center"></vxe-table-column>
                  <vxe-table-column field="inlibtime" sortable title="入库时间" width="120"></vxe-table-column>
                  <vxe-table-column field="create_dt" title="创建时间" width="120" align="center"></vxe-table-column>
                  <vxe-table-column field="create_username" title="创建人" width="60" align="center"></vxe-table-column>
                  <vxe-table-column field="recieve_dt" title="接收时间" width="120" sortable></vxe-table-column>
                  <vxe-table-column field="recieve_username" title="接收人" width="60" sortable align="center"></vxe-table-column>
                  <vxe-table-column field="library_id" title="所在库位ID" width="70" align="center"></vxe-table-column>
                  <vxe-table-column field="reqtypename" title="申请单类别" width="80" align="center"></vxe-table-column>
                  <vxe-table-column field="tube_color" title="试管颜色" width="80"></vxe-table-column>
                  <vxe-table-column field="showrptunitid" sortable title="检验报告单元" width="110">
                      <template v-slot="{ row }">
                          <div>
                              <span>{{ row.showrptunitname }}</span>
                          </div>
                      </template>
                  </vxe-table-column>
                  <vxe-table-column field="showsampledate" sortable title="检测日期" width="100" :formatter="['toDateString', 'yyyy-MM-dd']"> </vxe-table-column>
                  <vxe-table-column field="idhead" title="号段" width="60"></vxe-table-column>
                  <vxe-table-column field="rpt_itemcode" title="报告项目代码" width="80"></vxe-table-column>
                  <vxe-table-column field="defaultval" title="默认值" width="60"></vxe-table-column>
                  <vxe-table-column field="req_itemcode" title="申请项目代码" width="80"></vxe-table-column>
              </vxe-table>
          </div>
          <div class="pagerfix">
              <vxe-pager :loading="mainloading" :current-page="tablePage.currentPage" :page-size="tablePage.pageSize" :page-sizes="[100, 200, 500, 1000, 2000, 5000]" :total="tablePage.total" :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']" @page-change="handlePageChange"> </vxe-pager>
          </div>
      </div>
      <el-dialog width="auto" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="已使用标本号" v-if="showsamplenoVisible" :visible.sync="showsamplenoVisible">
          <div style="width: 300px; height: 200px">
              <vxe-table :data="showsamplenoData" :select-config="{ tigger: 'row' }" @cell-dblclick="showsampleDblClick" :sort-config="{ trigger: 'cell' }" :scroll-y="{ rHeight: '50px' }" height="auto" highlight-current-row resizable border show-header-overflow="ellipsis" show-overflow="ellipsis" header-align="center" size="mini" width="100%">
                  <vxe-table-column field="startno" title="开始标本号" width="80px" sortable></vxe-table-column>
                  <vxe-table-column field="endno" title="结束标本号" width="80px" sortable></vxe-table-column>
                  <vxe-table-column field="num" title="数量" width="50px" sortable align="center"></vxe-table-column>
              </vxe-table>
          </div>
          <div style="width: 100%; text-align: right; padding-top: 5px">
              <el-button @click="ShowInusedSampleno">刷新</el-button>
              <el-button @click="showsamplenoVisible = false">关闭</el-button>
          </div>
      </el-dialog>
  </div>
</template>

<script type="text/javascript">
import XE from "xe-utils"; //引入工具类
import current from "../../../../element-ui/packages/table/src/store/current";
export default {
  name: "LIS351",
  data() {
      return {
          keyConfig: {
              isDel: true,
              isTab: true,
              isEdit: true,
              isArrow: true,
          },
          itemData: [],
          mainData: [],
          itemloading: false,
          mainloading: false,
          inlibtimebegin: this.$pub.InitDateTime2(30).datefrom,
          inlibtimeend: this.$pub.InitDateTime2(30).dateto,
          sampledatebegin: "",
          sampledateend: "",
          rptunitid: "",
          isonlyoperate: "",
          idnumberbegin: "",
          idnumberend: "",
          isfullcontent: "0",
          sampledate: XE.toDateString(new Date(), "yyyy-MM-dd"),
          sampleno: "",
          isautorank: "1",
          samplecount: "",
          // isshowrptitem: "1",
          sel_itemcombid: "",
          isbranchsampleNo: "3",
          rowindex: 0,
          newsampleno: 0,
          totalcnt: 0,
          successcnt: 0,
          failcnt: 0,
          errormsg: "",
          dialogvisible: false,
          successmsg: "",
          rptunitOption: [],
          idhead: "",
          havedata: "",
          onmachinedata: [],
          mainselrow: "",
          headstrs: "",
          headOption: "",
          bUseFlag: true,
          printUseFlag: true,
          tableDataResultAll: [],
          tableDataResultS: [],
          tableColumnResultAll: [],
          textvalueshow: false,
          labgroupid: 0,
          labgroupidval: "",
          negativeval: "阴性",
          showsamplenoVisible: false,
          showsamplenoData: [], //已使用标本号数据
          isresultstredit: true,
          qbarcode: "",
          pat_name: "",
          rptitemcode: "",
          colorOption: [],
          pickerOptions: {
              shortcuts: [
                  {
                      text: "今天",
                      onClick(picker) {
                          picker.$emit("pick", XE.toDateString(new Date(), "yyyy-MM-dd 00:00:00"));
                      },
                  },
              ],
          },
          tablePage: {
              currentPage: 1,
              pageSize: 1000,
              total: 0,
          },
          sortorder:"",
          sortOption:[],
           pickerOptions: {
              shortcuts: [
                  {
                      text: "今天",
                      onClick(picker) {
                          picker.$emit("pick", XE.toDateString(new Date(), "yyyy-MM-dd"));
                      },
                  },
              ],
          }, 
          txtcontent:"",
          pttypecode:"",
          patno:"",
          rptunitname: "",
          pttypename: "",
          labgroupname: "",
          sel_itemcomname: "",
          rptitemname: "",
          isallcontain:"0",
      };
  },
  created() {
      this.sortorder =  localStorage.getItem("lis351sortorder");
      this.InitOption();
  },
  mounted() {},
  updated() {},
  methods: {
      handlePageChange({ currentPage, pageSize }) {
          this.tablePage.currentPage = currentPage;
          this.tablePage.pageSize = pageSize;
          this.Query();
      },
      InitOption() {
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS351",
                  method: "post",
                  data: {
                      action: "InitOption",
                  },
              })
              .then((res) => {
                  this.rptunitOption = res.rptunitOption;
                  this.headstrs = res.headstrs;
                  this.headOption = res.headOption;
                  this.labgroupid = res.labgroupid - 0;
                  this.labgroupidval = res.labgroupid;
                  this.labgroupname = res.labgroupname;
                  this.colorOption = res.colorOption;
                  this.sortOption = res.sortoption;
                  this.sortorder = "";
                  this.txtcontent = "蓝色：需要在【"+res.overhour+"】小时内发布报告，红色：已超时，报告未发布"
              });
      },

      Query() {
          let seldata = this.$refs.itemtable.getSelectRecords();
          var itemcodes = "";
          if (seldata.length > 0) {
              seldata.forEach((element) => {
                  itemcodes += "'" + element.rpt_itemcode + "'" + ",";
              });
          }
          const loading = this.$loading({
              lock: true,
              text: "Loading",
              spinner: "el-icon-loading",
              background: "rgba(0, 0, 0, 0.7)",
          });
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS351",
                  method: "post",
                  data: {
                      action: "querydata",
                      inlibtimebegin: this.inlibtimebegin, //核收时间
                      inlibtimeend: this.inlibtimeend,
                      idhead: this.idhead, // 库位类型
                      idnumberbegin: this.idnumberbegin, // 库位号
                      idnumberend: this.idnumberend,
                      isbranchsampleNo: this.isbranchsampleNo, // 是否有报告信息
                      itemcodes: itemcodes, // 勾选的报告项目
                      headstrs: this.headstrs, // 样本数量
                      barcode: this.qbarcode, // 条码号
                      rptitemcode: this.rptitemcode, // 报告项目
                      sampledatebegin: this.sampledatebegin, // 检验时间
                      sampledateend: this.sampledateend, // 检验时间
                      pat_name: this.pat_name, // 姓名
                      isallcontain:this.isallcontain,//是否包含所有报告项目
                      pagesize: this.tablePage.pageSize,
                      currentpage: this.tablePage.currentPage,
                      sortorder:this.sortorder,
                      pttypecode:this.pttypecode,
                      patno:this.patno,
                  },
              })
              .then((res) => {
                  if (res.data.length > 0) {
                      let tdindex = 1;
                      let cworkid = "";
                      for (let index = 0; index < res.data.length; index++) {
                          let element = res.data[index];
                          if (cworkid == "") {
                              element.seqno = tdindex;
                              cworkid = element.workid;
                          } else if (cworkid == element.workid) {
                              element.seqno = tdindex;
                          } else {
                              tdindex++;
                              element.seqno = tdindex;
                              cworkid = element.workid;
                          }
                      }
                      this.tablePage.total = res.totalcnt;
                      this.mainData = res.data;
                      this.$refs.mainTable.setCurrentRow(res.data[0]);
                  } else {
                      this.mainData = res.data;
                  }
                  loading.close();
                  // 记录查询时选择的排序方式
                  localStorage.setItem("lis351sortorder", this.sortorder); 
              })
              .catch((e) => {
                  loading.close();
                  this.$alert(e);
              });
      },
      ResultActive({ row, rowIndex, $rowIndex, column, columnIndex, $columnIndex, cell }) {
          if (column.property == "result_str") {
              this.iconclass = "el-icon-arrow-down";
              this.textvalueshow = false;
              this.QueryResultAll(row.rpt_itemcode, 0);
          }
      },
      QueryResultAll(rptitemcode, rekind) {
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS310",
                  method: "post",
                  data: {
                      action: "getrptitemval",
                      rpt_itemcode: rptitemcode,
                      resultkind: rekind,
                      rptunitid: this.myrptunitid,
                  },
              })
              .then((res) => {
                  this.tableColumnResultAll = res.Cols;
                  this.tableDataResultAll = res.Data;
                  this.tableDataResultS = res.Data;
                  if (this.tableDataResultAll.length > 0) {
                      this.textvalueshow = true;
                  }
              });
      },

      ResultClose({ row, rowIndex, $rowIndex, column, columnIndex, $columnIndex, cell }) {
          if (column.property == "result_str") {
              if (row.result_str) {
                  var selectrow = this.tableDataResultAll.filter((item) => item.inputcode == row.result_str);
                  if (selectrow.length > 0) {
                      row.result_str = selectrow[0].textvalue;
                  }
              }
              this.textvalueshow = false;
          }
      },
      ResultTextClick({ row }, rptrow) {
          rptrow.result_str = row.textvalue;
          rptrow.result_flag = row.result_flag;
          this.textvalueshow = false;
      },
      ResultMove(row, type, index, coltype) {
          if (type == 1) {
              if (index < this.$refs.mainTable.tableFullData.length - 1) {
                  var row = this.$refs.mainTable.tableFullData[index + 1];
                  this.$refs.mainTable.setCurrentRow(row);

                  this.$refs.mainTable.setActiveCell(row, coltype);
              }
          } else {
              if (index != 0) {
                  var row = this.$refs.mainTable.tableFullData[index - 1];
                  this.$refs.mainTable.setCurrentRow(row);

                  this.$refs.mainTable.setActiveCell(row, coltype);
              }
          }
      },

      NextFocus(index) {
          if (index > 2) return false;
          var that = this;
          var focusIndex = index + 1;
          setTimeout(function () {
              if (index == 2) {
                  that.$refs["input" + index].blur();
              }
              that.$refs["input" + focusIndex].focus();
          }, 1);
      },
      resultenter(rowIndex) {
          var thisrow = this.$refs.mainTable.tableFullData[rowIndex + 1];
          //if (hascol) thisrow = this.$refs.mainTable.getCurrentRow();
          this.$nextTick(() => {
              this.$refs.mainTable.setCurrentRow(thisrow);
              this.$refs.mainTable.clearSelected();
              this.$refs.mainTable.clearActived();
              this.$nextTick(() => {
                  this.$refs.mainTable.setActiveCell(thisrow, "result_str");
              });
          });
      },
      handleIconClick() {
          this.textvalueshow = !this.textvalueshow;
      },
      // 项目组合 选中事件
      reportitemcombchange(val, name) {
          this.sel_itemcombid = val;
          this.sel_itemcomname = name;
          this.getrptitem();
      },
      branchsampleNochange(val) {
          if (val == "3") {
              this.isresultstredit = true;
              this.bUseFlag = true;
              this.printUseFlag = true;
              this.sampledatebegin = "";
              this.sampledateend = "";
          } else {
              this.isresultstredit = false;
              this.bUseFlag = false;
              this.printUseFlag = true;
          }
      },
      getrptitem() {
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS351",
                  method: "post",
                  data: {
                      action: "getLabRptItem",
                      // rptunitid: this.rptunitid,
                      itemcombid: this.sel_itemcombid,
                      // isshowrptitem: this.isshowrptitem,
                  },
              })
              .then((res) => {
                  this.itemData = res.data;
                  this.mainData = [];
              });
      },
      // 分配样本号
      branchsampleno() {
          this.havedata = [];
          let newsampledate = this.sampledate;
          if (newsampledate == "") {
              this.$alert("请选择标本日期！");
              return;
          }
          this.newsampleno = this.sampleno;
          if (this.newsampleno == "") {
              this.$message.error("请填写起始标本号！");
              this.$refs.newsampleno.focus();
              return;
          }
          var nowdata = this.$pub.InitDate();
          if(nowdata != this.sampledate){
              this.$confirm("检验日期【"+this.sampledate+"】与当前日期【"+nowdata+"】不一致,您确定要继续分配样本号吗？", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
          })
              .then(() => {
                  if (this.isautorank == "1") {
                      let maindata = this.mainData.filter((item) => item.checkitemcode == "" || item.checkitemcode == null);
                      // 开始编号
                      for (let index = 0; index < maindata.length; index++) {
                          var selrow = maindata[index];
                          selrow.showrptunitid = this.rptunitid;
                          let obj = this.rptunitOption.find((m) => m.data == this.rptunitid);
                          if (obj != undefined) {
                              selrow.showrptunitname = obj.display;
                          } else {
                              selrow.showrptunitname = this.rptunitid;
                          }
                          selrow.rptunitid = this.rptunitid;
                          selrow.showsampledate = this.sampledate;
                          selrow.newitemcode = selrow.rpt_itemcode;
                          if (this.havedata.length == 0) {
                              selrow.showsampleno = this.newsampleno;
                              selrow.newreportid = XE.toDateString(this.sampledate, "yyyyMMdd") + "-" + this.rptunitid + "-" + this.newsampleno;
                              this.newsampleno++;
                              this.sampleno = this.newsampleno;
                              this.havedata.push(selrow);
                          } else {
                              var ishave = false;
                              for (let index = 0; index < this.havedata.length; index++) {
                                  const element = this.havedata[index];
                                  if (element.barcode == selrow.barcode && element.rptitemgroups == selrow.rptitemgroups) {
                                      selrow.showsampleno = element.showsampleno;
                                      selrow.newreportid = element.newreportid;
                                      ishave = true;
                                      break;
                                  }
                              }
                              if (!ishave) {
                                  selrow.showsampleno = this.newsampleno;
                                  selrow.newreportid = XE.toDateString(this.sampledate, "yyyyMMdd") + "-" + this.rptunitid + "-" + this.newsampleno;
                                  this.newsampleno++;
                                  this.sampleno = this.newsampleno;
                                  this.havedata.push(selrow);
                              }
                          }
                      }

                      //this.getnext(maindata[this.rowindex]);
                  } 
                  else {
                          let selrow = this.$refs.mainTable.getCurrentRow();
                          selrow.showrptunitid = this.rptunitid;
                          let obj = this.rptunitOption.find((m) => m.data == this.rptunitid);
                          if (obj != undefined) {
                              selrow.showrptunitname = obj.display;
                          } else {
                              selrow.showrptunitname = this.rptunitid;
                          }
                          selrow.rptunitid = this.rptunitid;
                          selrow.showsampledate = this.sampledate;
                          selrow.newitemcode = selrow.rpt_itemcode;
                          selrow.showsampleno = this.newsampleno;
                          selrow.newreportid = XE.toDateString(this.sampledate, "yyyyMMdd") + "-" + this.rptunitid + "-" + this.newsampleno;
                          this.newsampleno++;
                          this.sampleno = this.newsampleno;
                  }
              })
              .catch(() => {});
          }
          else{
              if (this.isautorank == "1") {
                      let maindata = this.mainData.filter((item) => item.checkitemcode == "" || item.checkitemcode == null);
                      // 开始编号
                      for (let index = 0; index < maindata.length; index++) {
                          var selrow = maindata[index];
                          selrow.showrptunitid = this.rptunitid;
                          let obj = this.rptunitOption.find((m) => m.data == this.rptunitid);
                          if (obj != undefined) {
                              selrow.showrptunitname = obj.display;
                          } else {
                              selrow.showrptunitname = this.rptunitid;
                          }
                          selrow.rptunitid = this.rptunitid;
                          selrow.showsampledate = this.sampledate;
                          selrow.newitemcode = selrow.rpt_itemcode;
                          if (this.havedata.length == 0) {
                              selrow.showsampleno = this.newsampleno;
                              selrow.newreportid = XE.toDateString(this.sampledate, "yyyyMMdd") + "-" + this.rptunitid + "-" + this.newsampleno;
                              this.newsampleno++;
                              this.sampleno = this.newsampleno;
                              this.havedata.push(selrow);
                          } else {
                              var ishave = false;
                              for (let index = 0; index < this.havedata.length; index++) {
                                  const element = this.havedata[index];
                                  if (element.barcode == selrow.barcode&& element.rptitemgroups == selrow.rptitemgroups) {
                                      selrow.showsampleno = element.showsampleno;
                                      selrow.newreportid = element.newreportid;
                                      ishave = true;
                                      break;
                                  }
                              }
                              if (!ishave) {
                                  selrow.showsampleno = this.newsampleno;
                                  selrow.newreportid = XE.toDateString(this.sampledate, "yyyyMMdd") + "-" + this.rptunitid + "-" + this.newsampleno;
                                  this.newsampleno++;
                                  this.sampleno = this.newsampleno;
                                  this.havedata.push(selrow);
                              }
                          }
                      }

                      //this.getnext(maindata[this.rowindex]);
              } 
              else {
                      let selrow = this.$refs.mainTable.getCurrentRow();
                      selrow.showrptunitid = this.rptunitid;
                      let obj = this.rptunitOption.find((m) => m.data == this.rptunitid);
                      if (obj != undefined) {
                          selrow.showrptunitname = obj.display;
                      } else {
                          selrow.showrptunitname = this.rptunitid;
                      }
                      selrow.rptunitid = this.rptunitid;
                      selrow.showsampledate = this.sampledate;
                      selrow.newitemcode = selrow.rpt_itemcode;
                      selrow.showsampleno = this.newsampleno;
                      selrow.newreportid = XE.toDateString(this.sampledate, "yyyyMMdd") + "-" + this.rptunitid + "-" + this.newsampleno;
                      this.newsampleno++;
                      this.sampleno = this.newsampleno;
              }
          }
      },

      DataSelect({ row, rowIndex }) {
          this.mainselrow = row;
      },

      // 上机检测
      onmachinedetection() {
          this.bUseFlag = false;
          this.printUseFlag = false;
          this.onmachinedata = this.mainData.filter((item) => item.newitemcode != "");
          if (this.onmachinedata.length == 0) {
              this.$message.warning("没有需上机/检测得数据！");
              this.bUseFlag = true;
              this.printUseFlag = true;
              return;
          }
          this.rowindex = 0;
          this.onmachinenext(this.onmachinedata[this.rowindex]);
      },
      onmachinenext(row) {
          let element = row;
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS351",
                  method: "post",
                  data: {
                      action: "onmachinedetection",
                      datainfo: element,
                      rptunitid: this.rptunitid,
                      sampledate: this.sampledate,
                  },
              })
              .then((res) => {
                  element.inputresult = res.msg;
                  if (res.flag == "1") {
                      element.newitemcode = "";
                  } else if (res.flag == "-1") {
                      this.$message.error(res.msg);
                  }

                  this.rowindex++;
                  if (this.rowindex < this.onmachinedata.length) {
                      this.onmachinenext(this.onmachinedata[this.rowindex]);
                  } else {
                      this.bUseFlag = true;
                      this.printUseFlag = true;
                  }
              });
      },

      // 清空样本号
      clearsampleno() {
          let maindata = this.mainData;
          maindata.forEach((element) => {
              if (element.inputresult == "") {
                  element.newreportid = "";
                  element.showrptunitid = "";
                  element.showsampledate = "";
                  element.showsampleno = "";
                  element.newitemcode = "";
              }
          });
      },

      ResultClass(row) {
          var stylestr = "padding:0 3px;";
          if (this.colorOption.resultcolor_mode == "1") stylestr += "color:";
          else stylestr += "background-color:";
          var flag = row.result_flag;

          switch (flag) {
              case "M":
                  stylestr += this.colorOption.resultcolor_m;
                  break;
              case "H":
                  stylestr += this.colorOption.resultcolor_h;
                  break;
              case "L":
                  stylestr += this.colorOption.resultcolor_l;
                  break;
              case "P":
                  stylestr += this.colorOption.resultcolor_p;
                  break;
              case "W":
                  stylestr += this.colorOption.resultcolor_w;
                  break;
              case "E":
                  stylestr += this.colorOption.resultcolor_e;
                  break;
              case "Q":
                  stylestr += this.colorOption.resultcolor_w;
                  break;
              default:
                  stylestr += this.colorOption.resultcolor_m;
                  break;
          }

          if (row.result_str == "未做") {
              stylestr += ";color: #0095D9";
          }
          return stylestr;
      },

      predtClass(row) {
          var stylestr = "padding:0 3px;background-color:";
          var flag = row.overflag;
          switch (flag) {
              case 1:
                  stylestr += " #33ccff";
                  break;
              case 2:
                    stylestr += " #ff3333";
                  break;
              default:
                  break;
          }
          return stylestr;
      },

      ReusltflagName(flag) {
          switch (flag) {
              case "M":
                  return "正常";
              case "H":
                  return "偏高";
              case "L":
                  return "偏低";
              case "P":
                  return "阳性";
              case "W":
                  return "弱阳性";
              case "E":
                  return "错误";
              case "Q":
                  return "弱阳性";
              default:
                  return "";
          }
      },
      rptunitChange(code, name) {
          this.rptunitid = code;
          this.rptunitname = name;
      },
      pattypeChange(code, name) {
          this.pttypecode = code;
          this.pttypename = name;
      },
      rptitemChange(code, name) {
          this.rptitemcode = code;
          this.rptitemname = name;
      },
      btnExport() {
          let tableColumn = this.$refs.mainTable.getColumns();
          let extableColumn = [];
          tableColumn.forEach((item) => {
              extableColumn.push({ title: item.title, field: item.property });
          });
          let filtertxt = this.getExportFilter();
          this.$pub.exportTableExcel(this.mainData, extableColumn, "LIS351标本查询/检测数据.xlsx", filtertxt);
      },
      // 获取当前导出文件的所有查询条件
      getExportFilter() {
          let filtertxt = "入库时间:" + XE.toDateString(this.inlibtimebegin, "yyyy-MM-dd") + "至" + XE.toDateString(this.inlibtimeend, "yyyy-MM-dd") + "; ";
          if(this.qbarcode) filtertxt += "条码号:" + this.qbarcode + "; ";
          if(this.patno) filtertxt += "病历号:" + this.patno + "; ";
          if(this.rptunitid) filtertxt += "报告单元:" + this.rptunitname + "; ";
          if(this.idhead) filtertxt += "库位类型:" + this.getOptionName(this.headOption.filter((item) =>  this.idhead ==item.value)) + "; ";
          if(this.idnumberbegin || this.idnumberend) filtertxt += "库位号:" + this.idnumberbegin + "至" + this.idnumberend+ "; ";
          if(this.pat_name) filtertxt += "姓名:" + this.pat_name + "; ";
          if(this.pttypecode) filtertxt += "病人类型:" + this.pttypename + "; ";
          if(this.sampledate) filtertxt += "检验日期:" + XE.toDateString(this.sampledate, "yyyy-MM-dd") + "; ";
          if(this.sampleno) filtertxt += "起始标本号:" + this.sampleno + "; ";
          if(this.sel_itemcombid) filtertxt += "项目组合:" + this.sel_itemcomname + "; ";
          filtertxt += this.getReportInfoName() + "; ";
          if(this.rptitemcode) filtertxt += "报告项目:" + this.rptitemname + "; ";
          if(this.sortorder) filtertxt += "排序方式:" + this.getOptionName(this.sortOption.filter((item) =>  this.sortorder ==item.data)) + "; ";
          if(this.isautorank == "1") filtertxt += "输入样本号后自动往下排列; ";
          if(this.sampledatebegin || this.sampledateend) filtertxt += "检测日期:" + XE.toDateString(this.sampledatebegin, "yyyy-MM-dd") + "至" + XE.toDateString(this.sampledateend, "yyyy-MM-dd") + "; ";
          if(this.labgroupidval) filtertxt += "检验工作组:" + this.labgroupname + "; ";
          return filtertxt;
      },
      getReportInfoName() {
          let name = "";
          switch(this.isbranchsampleNo) {
              case "0":
                  name = "全部信息";
                  break;
              case "1":
                  name = "已生成报告信息";
                  break;
              case "2":
                  name = "已生成需复查报告信息";
                  break;
              case "3":
                  name = "未生成报告信息";
                  break;
          }
          return name;
      },
      getOptionName(option) {
          if (option && option.length > 0) {
              let optionname = "";
              option.forEach((item) => {
                  if(item.hasOwnProperty("display")) {
                      optionname += item.display + ",";
                  } else {
                      optionname += item.label + ",";
                  }
              });
              return optionname.substring(0, optionname.length - 1);
          } else {
              return "";
          }
      },
      printBtn(index) {
          var that = this;
          if (typeof jsObj != "undefined") {
              let data = this.$refs.mainTable.afterFullData;
              console.info(data);
              let intIndex = 0;
              let loopworkid = "";
              // data.forEach((e) => {
              //     if (loopworkid != e.workid) {
              //         intIndex++;
              //         e.seqno = intIndex;
              //         loopworkid = e.workid;
              //     } else {
              //         e.seqno = intIndex;
              //     }
              // });
              let column = this.$refs.mainTable.getTableColumn().tableColumn;
              let columns = this.$pub.InitColumn(column);
              let str = JSON.stringify(columns);
              str += "\r";
              str += JSON.stringify(data);
              let sql = btoa(encodeURIComponent(str));
              if (data.length > 0) {
                  if (index == "2") {
                      //设计
                      const rload = this.$pub.openLoading(this, "正在打开报表设计器，请稍候……");
                      jsObj.SetCustomJsonPrintConfig("5100", sql, this.userno, "标本查询与检测清单样式");
                      rload.close();
                  } else {
                      //打印

                      jsObj.PrintCustomJsonReport("5100", sql, this.userno, "标本查询与检测清单样式", "");
                  }
              } else {
                  this.$alert("没有获取到数据！", "提示");
              }
          } else {
              this.$alert("请使用" + this.$pub.clientname + "打开！", "提示");
          }
      },

      // 一键阴性
      setnegative() {
          let list = this.mainData;

          for (let index = 0; index < list.length; index++) {
              let element = list[index];
              if (element.result_str == "未做" && element.inputresult != "成功") {
                 if( element.defaultval  != "" && element.defaultval  != null ){
                      element.result_str =element.defaultval;
                 }
                 else{
                      element.result_str = "阴性(-)";
                 }
                 
              }
          }
      },
      rowspanMethod({ row, $rowIndex, column, data }) {
          let fields = ["inlib_dt", "workid", "seqno"];
          let cellValue = row[column.property];
          if (cellValue && fields.includes(column.property)) {
              let prevRow = data[$rowIndex - 1];
              let nextRow = data[$rowIndex + 1];
              if (prevRow && prevRow[column.property] === cellValue) {
                  return { rowspan: 0, colspan: 0 };
              } else {
                  let countRowspan = 1;
                  while (nextRow && nextRow[column.property] === cellValue) {
                      nextRow = data[++countRowspan + $rowIndex];
                  }
                  if (countRowspan > 1) {
                      return { rowspan: countRowspan, colspan: 1 };
                  }
              }
          }
      },

      ShowInusedSampleno() {
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS310",
                  method: "post",
                  data: {
                      action: "showusedsampleno",
                      rptunitid: this.rptunitid,
                      sampledate: this.sampledate,
                  },
              })
              .then((res) => {
                  if (!res.hasOwnProperty("errcode")) {
                      this.showsamplenoData = [];
                      for (let i = 0; i < res.length; i++) {
                          var samplenos = res[i].Item1;
                          var samplearr = samplenos.split("-");
                          var num = res[i].Item2;
                          this.showsamplenoData.push({ startno: samplearr[0], endno: samplearr[1], num: num });
                      }

                      this.showsamplenoVisible = true;
                  } else this.$confirm(res.errmsg, "错误");
              })
              .catch((err) => {
                  console.log("instrdataerr:" + err);
              });
      },
      samplenochange(selrow) {
          if (selrow.showsampleno != "" && selrow.inputresult != "成功") {
              selrow.showrptunitid = this.rptunitid;
              let obj = this.rptunitOption.find((m) => m.data == this.rptunitid);
              if (obj != undefined) {
                  selrow.showrptunitname = obj.display;
              } else {
                  selrow.showrptunitname = this.rptunitid;
              }
              selrow.rptunitid = this.rptunitid;
              selrow.showsampledate = this.sampledate;
              selrow.newitemcode = selrow.rpt_itemcode;
              selrow.newreportid = XE.toDateString(this.sampledate, "yyyyMMdd") + "-" + this.rptunitid + "-" + selrow.newsampleno;
          } else {
              selrow.newreportid = "";
              selrow.showrptunitid = "";
              selrow.showsampledate = "";
              selrow.showsampleno = "";
              selrow.newitemcode = "";
          }
      },
       DateBackGround() {
          var datenow = this.$pub.InitDate();
          if (datenow > this.sampledate) {
              return "beforedate";
          } else if (datenow < this.sampledate) {
              return "overdate";
          } else {
              return "";
          }
      },
  },
};
</script>

<style scoped>
.pagetop {
  width: 100%;
  /* height: 105px; */
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}

.pagecenter {
  position: absolute;
  top: 153px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.middle-center {
  position: absolute;
  height: 100%;
  left: 351px;
  right: 0px;
  overflow: auto;
}
.middle-left {
  position: absolute;
  height: 100%;
  width: 350px;
  left: 0px;
  top: 0;
}
.poppagetop {
  width: 100%;
  height: 40px;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  position: absolute;
  border: 1px solid #ccc;
  z-index: 999;
}
.poppagecenter {
  position: absolute;
  top: 50px;
  width: 100%;
  left: 0;
}
.popmiddle-left {
  background-color: aqua;
  position: absolute;
  height: 450px;
  width: 480px;
  left: 0px;
  overflow: auto;
}
.popmiddle-center {
  position: absolute;
  -webkit-box-align: center;
  height: 100%;
  left: 485px;
  right: 485px;
}
.popmiddle-right {
  position: absolute;
  top: 0;
  bottom: 0;
  height: 450px;
  width: 480px;
  right: 0px;
  border: 1px solid #ccc;
}
.table1style tr td {
  padding: 0px 2px 0px 5px;
  white-space: nowrap;
}
.reqitem-dialog {
  position: absolute;
  z-index: 10000;
}

.pagerfix {
  height: 40px;
  position: fixed;
  bottom: 40px;
  right: 10px;
  width: 80%;
}
::v-deep .ResultTxtTable.vxe-table .vxe-body--row td {
  background-color: #fff !important;
}
::v-deep .ResultTxtTable.vxe-table .vxe-body--row.row--hover td {
  background-color: #d7f1fd !important;
}

::v-deep .overdate {
  background-color: #80ff80 !important;
}
::v-deep .beforedate {
  background-color: #ffff80 !important;
}
</style>